<!--
 * @Author: dumin
 * @Date: 2025-06-29 16:20:00
 * @Description: 批量云币导入结果
 * @LastEditors: dumin
 * @LastEditTime: 2025-08-28 16:17:17
-->
<template>
  <el-dialog :visible.sync="dialogVisible" width="60%" @open="open" title="导入结果">
    <div class="import-wrapper">
      <div class="import-wrapper__title">导入结果统计</div>
      <div class="import-wrapper__content">导入验证成功
        <el-link type="success">{{ successNum }}</el-link>条，导入验证失败
        <el-link type="danger">{{ failureNum }}</el-link>条
      </div>

      <div class="import-wrapper__title">表格错误内容</div>
      <div class="import-wrapper__content">
        <el-table :data="datas">
          <el-table-column type="index" label="序号" width="55" :align="'center'" />
          <el-table-column prop="authCode" label="店铺授权码" />
          <el-table-column prop="storeName" label="店铺名称" />
          <el-table-column prop="companyName" label="经销商名称" />
          <el-table-column prop="type" label="云币类型" />
          <el-table-column prop="num" label="赠送数量" />
          <el-table-column prop="orderCustomerCode" label="订单客户编号" />
          <el-table-column prop="reason" label="赠送原因" />
          <el-table-column prop="errorMsg" label="失败原因" />
        </el-table>
      </div>
    </div>


    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <slot name="batch-upload"></slot>
      <el-button type="primary" @click="submitForm()" :disabled="!(detail && detail.uuid)" :loading="loading">确认发放</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  bonusAddExcelImportSubmit
} from '@/api/goodsExchange';
export default {
  props: {
    show: { type: Boolean, default: false },
    detail: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      successNum: 0,
      failureNum: 0,
      datas: [],
      loading: false
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.show;
      },
      set(val) {
        this.$emit('update:show', val);
      },
    },
  },
  methods: {
    open() {
      if (this.detail) {
        this.successNum = this.detail.successNum;
        this.failureNum = this.detail.failureNum;
        this.datas = this.detail.datas;
      } else {
        this.successNum = 0;
        this.failureNum = 0;
        this.datas = [];
      }
    },
    submitForm() {
      if (this.detail && this.detail.uuid) {
        this.loading = true
        bonusAddExcelImportSubmit({
          uuid: this.detail.uuid
        }).then(res => {
          if (res.code == 1) {
            this.$message.success(res.message);
            this.dialogVisible = false
            this.$emit('refresh');
          } else {
            this.$message.error(res.message);
          }
        }).finally(() => {
          this.loading = false
        })
      }
    }
  },
}
</script>

<style lang="scss" scoped>
.import-wrapper {
  max-height: 500px;
  overflow: auto;

  &__title {
    font-weight: bold;
    margin-bottom: 16px;
  }

  &__content {
    margin-bottom: 16px;
  }
}
</style>